// Copyright by LunaSec (owned by Refinery Labs, Inc)
//
// Licensed under the Business Source License v1.1
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
// https://github.com/lunasec-io/lunasec/blob/master/licenses/BSL-LunaTrace.txt
//
// See the License for the specific language governing permissions and
// limitations under the License.
package advisory

import (
	"fmt"
	"strings"

	"github.com/lunasec-io/lunasec/lunatrace/gogen/gql/types"
)

func MapStringToPackageManager(namespace string) (types.PackageManager, error) {
	language := strings.ToLower(namespace)

	switch language {
	case "maven":
		return types.Maven, nil
	case "npm":
		return types.NPM, nil
	case "packagist":
		return types.Packagist, nil
	case "rubygems":
		return types.RubyGems, nil
	case "go":
		return types.Go, nil
	case "nuget":
		return types.NuGet, nil
	case "pypi":
		return types.PyPi, nil
	case "crates.io":
		return types.CratesIo, nil
	}
	return "", fmt.Errorf("unable to find package manager for %s", language)
}
